package com.example.imtoken.modules.main.wallet.manage.wallet

import com.blankj.utilcode.util.ClickUtils
import com.blankj.utilcode.util.StringUtils
import com.chad.library.adapter.base.BaseDelegateMultiAdapter
import com.chad.library.adapter.base.delegate.BaseMultiTypeDelegate
import com.chad.library.adapter.base.viewholder.BaseDataBindingHolder
import com.example.imtoken.R
import com.example.imtoken.databinding.ItemManageWalletBinding
import com.example.imtoken.entitys.app.WalletsEntity

class WalletAdapter(val type: Int) :
    BaseDelegateMultiAdapter<WalletsEntity, BaseDataBindingHolder<ItemManageWalletBinding>>(
    ) {

    init {
        setMultiTypeDelegate(object : BaseMultiTypeDelegate<WalletsEntity>() {
            override fun getItemType(data: List<WalletsEntity>, position: Int): Int {
                return when (data[position].name) {
                    StringUtils.getString(R.string.addToken) -> 1
                    else -> 0
                }
            }

        })
        getMultiTypeDelegate()
            ?.addItemType(0, R.layout.item_manage_wallet)
            ?.addItemType(1, R.layout.item_manage_add_wallet)
    }

    override fun convert(
        holder: BaseDataBindingHolder<ItemManageWalletBinding>,
        item: WalletsEntity
    ) {
        when (holder.itemViewType) {
            0 -> {
                holder.dataBinding?.item = item
                holder.dataBinding?.type = type
            }
            1 -> {

            }
        }
        ClickUtils.applyGlobalDebouncing(holder.itemView) {
            setOnItemClick(it, holder.adapterPosition)
        }
    }


}